//
//  UserInfo.swift
//  EastNetWorkProject
//
//  Created by hlt on 2023/10/30.
//

import Foundation
import UIKit

@objcMembers class UserInfo:NSObject,NSSecureCoding{
    static var supportsSecureCoding: Bool{
        return true
    }
    
    
    var username = ""
    var user_id = ""
    var open_id = ""
    var weixin = ""
    var face = ""
    var token = ""
    var usermob = ""
    var login_name = ""
    var usercontact = ""
    var userpass = ""
    
    
//    static var supportsSecureCoding: Bool {
//        return true
//    }
    required override init() {
        super.init()
    }
    // 从object 解析回来
    required init?(coder: NSCoder) {
        super.init()

        username = coder.decodeObject(forKey: "username") as? String ?? ""
        user_id = coder.decodeObject(forKey: "user_id") as? String ?? ""
        open_id = coder.decodeObject(forKey: "open_id") as? String ?? ""
        token  = coder.decodeObject(forKey: "token") as? String ?? ""
        login_name = coder.decodeObject(forKey: "login_name") as? String ?? ""
    }

    // 编码成object
    func encode(with coder: NSCoder) {
        coder.encode(username, forKey: "username")
        coder.encode(user_id, forKey: "user_id")
        coder.encode(open_id, forKey: "open_id")
        coder.encode(token, forKey: "token")
        coder.encode(login_name, forKey: "login_name")
    }
    
    static var shareInfo:UserInfo?
    
    func clear(){
        UserInfo.shareInfo?.username = ""
        UserInfo.shareInfo?.user_id = ""
        UserInfo.shareInfo?.open_id = ""
        UserInfo.shareInfo?.weixin = ""
        UserInfo.shareInfo?.face = ""
        UserInfo.shareInfo?.token = ""
        UserInfo.shareInfo?.usermob = ""
        UserInfo.shareInfo?.login_name = ""
        UserInfo.shareInfo?.usercontact = ""
        UserInfo.shareInfo?.userpass = ""
    }
    
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
    }
    
}
